package com.itheima.admin.mapper;

import com.itheima.admin.pojo.Employee;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;

import java.util.List;

/**
 * @Author longbosheng
 * @Date 2022/6/11 14:36
 * @PackageName:com.itheima.mapper
 * @ClassName: EmployeeLoginMapper
 * @Description: TODO
 * @Version 1.0
 */
@Mapper
public interface EmployeeMapper {
    /**
     * 查询用户名是否重复/查询状态是否被禁用
     * @param employee
     * @return
     */
    @Select("select * from employee where username = #{username}")
    Employee selectStatus(Employee employee);
    /**
     * 员工登录
     * @param employee
     * @return
     */
    @Select("select * from employee where username = #{username} and password = #{password} and status = 1")
    Employee login(Employee employee);

    /**
     * 员工添加
     * @param employee
     * @return
     */
    @Insert("insert into employee(username,name,phone,sex,idNumber,create_time,create_user) values(#{username},#{name},#{phone},#{sex},#{idNumber},now(),#{createUser})")
    int insertEmployee(Employee employee);

    /**
     * 分页查询全部
     * @param offset
     * @param pagesize
     * @return
     */
    @Select("select * from employee limit #{offset},#{pagesize}")
    List<Employee> showEmployee(int offset, int pagesize);

    /**
     * 查询总条数
     * @return
     */
    @Select("select count(*) from employee")
    int selectCount();
    /**
     * 按名字分页查询
     * @param name
     * @param offset
     * @param pagesize
     * @return
     */
    @Select("select * from employee where name =#{name} limit #{offset},#{pagesize}")
    List<Employee> selectEmployeeByName(String name, int offset, int pagesize);

    /**
     * 查询总条数
     * @param name
     * @return
     */
    @Select("select count(*) from employee where name = #{name}")
    int selectCountByName(String name);

    /**
     * 按照id查询员工
     * @param id
     * @return
     */
    @Select("select * from employee where id = #{id}")
    Employee selectEmployeeById(Integer id);

    /**
     * 启用/禁用/修改员工信息
     * @param employee
     * @return
     */
    int updateEmployee(Employee employee);
}
